#define _CRT_SECURE_NO_WARNINGS 1

class Solution {
public:
    bool IsSmallLetterOrNum(char a)
    {
        if (a <= 'z' && a >= 'a')
            return true;
        if (a >= '0' && a <= '9')
            return true;
        return false;
    }
    bool isPalindrome(string s) {
        for (auto& e : s)
        {
            if (e >= 'A' && e <= 'Z')
                e += ('a' - 'A');
        }
        int left = 0;
        int right = s.size() - 1;
        while (left < right)
        {
            while (!IsSmallLetterOrNum(s[left]))
            {
                if (++left > right)
                    return true;
            }
            while (!IsSmallLetterOrNum(s[right]))
            {
                if (--right < left)
                    return false;
            }
            if (s[left] != s[right])
                return false;
            ++left;
            --right;
        }
        return true;
    }
};